/**
 * Created by Administrator on 2017/5/14.
 */
//import direct from './mock/direct'

var templateHeader = {
  name    : 'c-header',
  template: `
    <header>
        <div class="txtc pd">剑灵角色信息查询</div>
    </header>
    `,
  data    : function () {
    return {}
  }
}
Vue.component('c-header', templateHeader);
var V = new Vue({
  el      : '#vueInstance',
  data    : {
    ajaxLoading: false,
    catalogry: 'all',
    page: 1,
    jumperPage: null,
    list: []
  },
  list : [],
  mounted(){
    this.getList()
  },
  computed: {},
  filters : {
    realIconPath: str => {
      if( str && str.indexOf('//') > -1 ) return str
      if (str === 'Acc_Belt_DarkLegendry_2-1Phase,1') {
        return 'http:\/\/dbrepo.ptbus.com\/data\/images\/201611\/4\/08f24f42b534f4445bed336d4a5c6cfb.png'
      }
      return str ? 'http://ossweb-img.qq.com/images/bangbang/home/tool/bns/item/' + str.split(',')[0] + '.png' : ''
    }
  },
  methods : {
    getList(targetPage){
      this.$set( this.$data, 'list', [] )
      this.$set( this.$data, 'ajaxLoading', true )
      this.catalogry && ajax('/consultings/haodf/' + this.catalogry + '/' + (targetPage ||this.page) ).then(res => {
        this.$set( this.$data, 'ajaxLoading', false )
        this.$set( this.$data, 'list', res.data.query.results ? res.data.query.results.ul.li : [])
        targetPage && res.data.query && this.$set( this.$data, 'page', targetPage)
      }) || alert('请输入角色名称!')
    },
    pageUp(){
      this.getList( parseInt(this.page) - 1 )
    },
    pageDown(){
      this.getList( parseInt(this.page) + 1 )
    },
    pageTo(){
      this.jumperPage && this.getList( parseInt(this.jumperPage) )
      this.jumperPage || alert('请输入页码!')
    }
  }
})
String.prototype.endWith=function(str){
  if(str==null||str==""||this.length==0||str.length>this.length)
    return false;
  if(this.substring(this.length-str.length)==str)
    return true;
  else
    return false;
  return true;
}
String.prototype.startWith=function(str){
  if(str==null||str==""||this.length==0||str.length>this.length)
    return false;
  if(this.substr(0,str.length)==str)
    return true;
  else
    return false;
  return true;
}
function deepCopy(source) {
  var result={};
  for (var key in source) {
    result[key] = /*typeof source[key]==='object'? deepCopy(source[key]): */source[key];
  }
  return result;
}
